/* 
 * Copyright (C) 2012 UTSChedule
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package utsc.apps.utschedule.ui;

import utsc.apps.utschedule.R;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockDialogFragment;

/**
 * This dialog fragment is a fully reusable component that displays a custom
 * message as a simple dialog. It is useful to show a simple message with no action handling.
 * 
 */
public class MessageDialogFragment extends SherlockDialogFragment{

	public static final String ARGS_TITLE_KEY="title";
	public static final String ARGS_MESSAGE_KEY="message";
	private TextView _txtMessage;
	private String _title;
	private String _message;
	public static final String TAG="MessageDialogFragment";
	
	/**
	 * Create a new message dialog by taking the given dialog title and content message.
	 * @param title
	 * @param message
	 * @return
	 */
	public static MessageDialogFragment newInstance(String title, String message){
		MessageDialogFragment fragment=new MessageDialogFragment();
		Bundle arguments=new Bundle();
		arguments.putString(ARGS_TITLE_KEY, title);
		arguments.putString(ARGS_MESSAGE_KEY, message);
		fragment.setArguments(arguments);
		return fragment;
	}
	
	public MessageDialogFragment() {
		super();
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Bundle args=getArguments();
		if (args!=null) {
			_title=args.getString(ARGS_TITLE_KEY);
			_message=args.getString(ARGS_MESSAGE_KEY);
		}
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v=inflater.inflate(R.layout.fragment_message_dialog, container,false);
		if (v!=null) {
			_txtMessage=(TextView) v.findViewById(R.id.frg_txt_message);
			getDialog().setTitle(_title);
			if (_txtMessage!=null) {
				_txtMessage.setText(_message);
			}
		}
		return v; 
	}
	
}
